/* $Id: UserRoleDAOImpl.java 
 * Copyright (C) 2011, TRAKHEES
 *  
 * Revision History
 *
 * Date  			Author 		    	Remarks
 * ---------------------------------------------------------------------------------
 *
 */
package ae.pcfc.etks.online.common.dao.provider;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import ae.pcfc.etks.online.common.dao.UserRoleDAO;
import ae.pcfc.etks.online.common.domain.Client;
import ae.pcfc.etks.online.common.domain.UserServiceSecurity;

@Repository
public class UserRoleDAOImpl extends BaseDAO implements UserRoleDAO {
	
	/**
	 * getClientsList
	 * 
	 * @see ae.pcfc.etks.online.common.dao.UserRoleDAO#getClientsList()
	 * 
	 */
	@SuppressWarnings("unchecked")
	public List<Client> getClientsList() {
		Criteria criteria =  getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(Client.class);
			return criteria.list();
	}

	/**
	 * getUserSecurityRoleList
	 * 
	 * @see ae.pcfc.etks.online.common.dao.UserRoleDAO#getUserSecurityRoleList(java.lang.String)
	 * 
	 */
	public List<String> getUserSecurityRoleList(String userName) {
		
		Criteria criteria =  getHibernateTemplate().getSessionFactory().getCurrentSession().createCriteria(UserServiceSecurity.class);
		criteria.add(Restrictions.eq("usSecurityUsername", userName));
		
		List<UserServiceSecurity> serviceSecurities = criteria.list();
		List<String> list = new ArrayList<String>();
		
		for(UserServiceSecurity security: serviceSecurities){
			
			list.add(security.getServiceRole().getSrSecurityRoleName());
		}
		
		return list;
	}
}
